<?php 
// // if(!empty($_POST['image'])){
// var_dump($_FILES);

// // }
// move_uploaded_file($_FILES['image']['tmp_name'],'./upload/'.$_FILES['image']['name']);
if(!empty($_POST)){
    if($_FILES['image']['error']==0){
        // move_uploaded_file($_FILES['image']['tmp_name'],'./upload/'.time().rand(100,10000).$_FILES['image']['name']);
        $path=uniqid('user').rand(100,500).$_FILES['image']['name'];
        move_uploaded_file($_FILES['image']['tmp_name'],'./upload/'.$path);

    }else{
        echo "上传失败"+$_FILES['image']['error'];
    }
}
//解决上传的同名的文件要给覆盖
//1.通过时间戳

// './upload/'.time().rand(100,10000).$_FILES['image']['name']
//2.通过uniqid()实现
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="./文件上传.php" enctype="multipart/form-data" method="post">
    <!-- <input type="hidden" name="MAX_FILE_SIZE" value="2"> -->
    <input type="file" name='image'>
    <input type="submit" value='上传' name="sub">
    </form>
</body>
</html>